home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 8
/
Night Owl CD-ROM (NOPV8) (Night Owl Publisher) (1993).ISO
/
020a
/
wildcard.arj
/
WILDCARD.PRG
< prev
Wrap
Text File
|
1990-12-24
|
3KB
|
71 lines
* Function: [<logical exp>] = K_WILDCARD(<char exp1>,<char exp2>)
* Params : <char exp1> is the target string to search
* <char exp2> is the mask to search the target with
* Purpose : Provide an alternative to concatenated SUBSTR() comparisons
* for the purpose of filtering databases primarily for SET
* FILTER TO or FOR/WHILE conditions. Basically anywhere
* string comparisons are needed.
* Example : REPORT FORM test TO PRINT FOR k_wildcard(textfield,"?89?i?")
* Returns : a logical .T. or .F.
* Author : Kim Bjork, AMG Inc., 12/23/90, CIS 74017,1576
* : Released for public usage. No warranty implied or granted.
* Notes : -<char exp1> can be any valid char string, ie. memvar or field.
* -<char exp2>, the mask, must be formed with question marks,
* ie. "??IS????", "32??????", "?whEre?iS??", etc.
* The example, "?whEre?iS??", is where this function makes
* a difference, otherwise, use SUBSTR().
* Of course, it will work without any wildcard characters
* but then why use it?
* -Any printable character other than a question mark
* is considered valid search criteria (a significant char).
* -If the mask string is longer than the target string, the
* mask string will be truncated to the length of the target.
* Processing will be slowed slightly if the mask string is
* longer than the target (more code executes).
* -The target and mask strings will be forced to upper case
* for the purpose of the search.
* -To speed up processing, remove the TYPE() checking portion
* of the code. If you want to take responsibility at the
* calling portion of your code, remove the mask length checking
* also.
* -This function in entirely inappropriate for large character
* strings. Was designed for memvar lengths of 15 chars or
* less. The longer the mask, the more iterations the
* FOR..NEXT loop has to perform.
* -Designed for use with Clipper S'87, Clipper 5.0 version
* is in CLIP5VER.PRG.
function k_wildcard
parameters t_, m_ && target, mask
private tl, ml, i
* check parameters
if type("t_") + type("m_") != "CC"
retu .F.
endif
tl = len(t_) && target length
ml = len(m_) && mask length
if ml > tl && mask longer than target?
ml = tl && mask length becomes same as target
m_ = substr(m_,1,tl) && truncate to target length
endif
* force to upper case
t_ = upper(t_)
m_ = upper(m_)
* replace the target with "?" chars from the mask (where appropriate)
for i = 1 to ml
if substr(m_,i,1) = "?" && not a significant char?
t_ = stuff(t_,i,1,"?") && replace target char with "?"
endif
next
* substring of target string same as the mask?
return iif(substr(t_,1,ml) = m_, .T., .F.)
* I would be very interested in improvements to this function.